package org.ef.anticheck;

import android.app.ListActivity;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class CallHistory extends ListActivity {

	private SimpleCursorAdapter myAdapter;

	@Override
	public void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		final String[] columns = new String[] { "name", "number" };
		final int[] names = new int[] { R.id.name, R.id.phone };

		final Cursor cursor = this.getContentResolver().query(
				CallLog.Calls.CONTENT_URI, null, null, null, null);
		this.startManagingCursor(cursor);

		this.myAdapter = new SimpleCursorAdapter(this, R.layout.callhistory,
				cursor,
				columns, names);
		this.setListAdapter(this.myAdapter);
	}

	@Override
	protected void onListItemClick(final ListView listView, final View view,
			final int position, final long id) {
		super.onListItemClick(listView, view, position, id);

		Log.i("xxxxxxxxxxxxxxxx", "id = " + id);

		final String action = this.getIntent().getAction();

		if (Intent.ACTION_PICK.equals(action)) {
			this.setResult(RESULT_OK, new Intent().setData(
					ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, id)));
			this.finish();
		}
	}
}